// ManualBot.cpp : Defines the entry point for the console application.
//

#define _CRT_SECURE_NO_DEPRECATE 1
#include "stdafx.h"

BZRC* myTeam;
vector <tank_t> *myTanks;
vector <DumbAgent> dumbAgents;

int _tmain(int argc, char* argv[])
{
	string pcHost;
	int nPort;

	if(argc < 2) {
		cout << "server: ";
		cin >> pcHost;
	}
	else {
		pcHost = argv[1];
	}
    if(argc < 3) {
		cout << "port: ";
		cin >> nPort;
	}
	else {
        nPort = atoi(argv[2]);
    }

	BZRC MyTeam = BZRC(pcHost.c_str(), nPort, false);
	if(!MyTeam.GetStatus()) {
		cout << "Can't connect to BZRC server." << endl;
		exit(1);
	}

	world_init(&MyTeam);
	while (true) {
		robot_pre_update();
		robot_update();
		robot_post_update();
		//Sleep(50);
	}

	MyTeam.Close();

	getchar();
	return 0;
}

double normalize_angle(double angle) {
	return angle;
}

void world_init(BZRC *my_team) {
	myTeam = my_team;
	myTanks = new vector <tank_t>();

	myTeam->get_mytanks(myTanks);
	for(int i = 0; i < myTanks->size(); i ++){
		dumbAgents.push_back(DumbAgent(&(*myTanks)[i], myTeam));
	}
}

void robot_pre_update() {
	
}

void robot_update() {
	std::vector<tank_t>::iterator itr = myTanks->begin();
	for(int i = 0; i < dumbAgents.size(); i ++){
		dumbAgents[i].DoAction();
	}
	/*while(itr != myTanks->end()) {
		myTeam->shoot((*itr).index);
		itr++;
	}*/
}
void robot_post_update() {
	
}


